#$Source: Volumes://MATEOR/prlserverapi/prlserverapi-gui.rc/initial.pm$
#$Date: June 19, 2012$
#$Revision: 0.01-0a$

use strict;
use Cwd;
package initial;

my $Revision = '0.01-0a';
my $cwd = Cwd::getcwd();

sub page{
  my($r) = @_;
  my $content = <<EOF;
    <!DOCTYPE html>
<html>
  <head>
    <title>PrlServerAPI $Revision server</title>
    <script language=javascript>
      <!--
      //Browser Support Code
      function xmlhttpPost(strURL, elementId){
        var xmlhttp;
        var self = this;
        var oDiv = document.getElementById(elementId);

        try{
          // Opera 8.0+, Mozilla, Safari
          self.xmlhttp = new XMLHttpRequest();
        }catch(e){
          // MS-IE :(
          try{
            self.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          }catch(e){
            try{
              self.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){
              // Unsupported browser or browser doesn't support AJAX
              
            }
          }
        }
        self.xmlhttp.open('GET', strURL, true);
        self.xmlhttp.setRequestHeader('Content-Type', 'text/html');
        self.xmlhttp.onreadystatechange = function(){
          if(self.xmlhttp.readyState == 4){
            updatepage(self.xmlhttp.responseText, oDiv);
          }
        }
        self.xmlhttp.send();
      }
      function updatepage(str, div){
        div.innerHTML = str;
      }
//      function infotable(){
//        xmlhttpPost('http://127.0.0.1:1234/default.pl?store.infotable&location=$cwd/prlserverapi-gui.rc/infotable.xml', 'void');
//        xmlhttpPost('/xml.0?l=infotable.xml', 'infotable');
//        xmlhttpPost('/xml.0?e=infotable.xml', 'void');
//      }
      function xmlhttpSend(strURL, elementId){
        var xmlhttp;
        var self = this;
       
        try{
          // Opera 8.0+, Mozilla, Safari
          self.xmlhttp = new XMLHttpRequest();
        }catch(e){
          // MS-IE :(
          try{
            self.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          }catch(e){
            try{
              self.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){
              // Unsupported browser or browser doesn't support AJAX
              
            }
          }
        }
        self.xmlhttp.open('GET', strURL, true);
        self.xmlhttp.setRequestHeader('Content-Type', 'text/html');
        self.xmlhttp.send();
      }
      //-->
    </script>
    <style type="text/css">
      div#content{
        float:left;
        border-style:outset;
        border-width:2px;
        border-color:blue;
        margin-left:15%;
        width:900px;
        padding:0px;
        background-color:black;
        color:#f0f0f0;
        text-align:center;
      }
      div.clear{
        clear:both;
      }
      div#navbar{
        border-style:solid;
        border-width:1px;
        border-color:red;
      }
      div#navbar a{
        text-decoration:none;
        color:#f0f0f0;
      }
      div#footer{
        border-style:solid;
        border-width:1px;
        border-color:purple;
        margin-top:90%;
        height:20px;
        text-align:center;
      }
      div.column{
        color:#f0f0f0;
        border-style:solid;
        border-width:1px;
        float:left;
      }
      div.cell{
        color:#f0f0f0;
        border-style:solid;
        border-width:1px;
      }
      div#infotable{
        margin-left:20%;
        margin-right:20%;
      }
    </style>
  </head>
  <body bgcolor="#A9A9A9">
    <div id="content">
      <h1>PrlServerAPI $Revision gui application example!</h1>
      <div id="navbar">
        <p>PrlServerAPI is a research project, creating an easy to use API for TCP/IP programming and communication in Perl.</p>
      </div>
      <div id="sampleapp">
        <form>
          <input type="button" value="Start the sample app!" onclick="JavaScript:xmlhttpPost('/sampleapp.initial', 'sampleapp');" />
        </form>
      </div>
      <div id="server">
        <form>
          <input type="button" value="Start the webserver!" onclick="JavaScript:xmlhttpPost('/startserver.display', 'server');" />
        </form>
      </div>
      <div id="serverinfo">
        <form>
          <input type="button" value="Get server info!" onclick="JavaScript:xmlhttpSend('http://127.0.0.1:1234/default.pl?store.infotable&location=$cwd/prlserverapi-gui.rc/infotable.xml', 'void');xmlhttpPost('/xml.0?l=infotable.xml', 'infotable');" />
        </form>
        <div id="infotable"></div>
      </div>
      <div id="footer">
        PrlServerAPI $Revision &copy; Copyright Matthew Caswell 2012
      </div>
    </div>
    <div class="clear" />
    <div class="void" />
  </body>
</html>
EOF
  return $content;
}
  
1;
